<template>
  <div class="wrapper" ref="wrapper">
    <!-- 顶部文字栏 -->
    <Title>商城首页</Title>
    <scroller style="top:60px">
      <div class="index">
        <!-- banner轮播图 -->
        <van-swipe class="my-swipe" :autoplay="2000" :show-indicators="false">
          <van-swipe-item v-for="item in indexData.banner" :key="item.id">
            <img :src="item.url" />
          </van-swipe-item>
        </van-swipe>
        <!-- 搜索栏 -->
        <van-search
          v-model="searchValue"
          disabled
          background="transparent"
          shape="round"
          placeholder="搜索商品"
          @click="goSearch"
        />
        <!-- 公告 -->
        <!-- 滚动消息模块 -->
        <van-notice-bar
          background="transparent"
          left-icon="volume-o"
          mode="closeable"
          :scrollable="false"
        >
          <van-swipe vertical class="notice-swipe" :autoplay="5000" :show-indicators="false">
            <van-swipe-item v-for="item in indexData.noticeBar" :key="item.id">{{item.text}}</van-swipe-item>
          </van-swipe>
        </van-notice-bar>
        <!-- 菜单导航栏 -->
        <van-grid :column-num="5" :border="false">
          <van-grid-item v-for="item in indexData.tabList" :key="item.id">
            <svg class="icon" aria-hidden="true">
              <!-- <use xlink:href="#icon-yinliao" /> -->
              <use :xlink:href="item.icon" />
            </svg>
            <p class="gridFontSize">{{item.text}}</p>
          </van-grid-item>
        </van-grid>
        <!-- 热销推荐 -->
        <div class="hotRecommend">热销推荐</div>
        <!-- 热销推荐列表 -->
        <div class="hotGoodsList">
          <!-- list -->
          <div class="gotGoods" v-for="item in indexData.sellWell" :key="item.id">
            <div class="hotText">
              <div class="title">{{item.name}}</div>
              <div class="oldNum">已售{{item.alt}}</div>
              <div class="price">{{item.price}}</div>
            </div>
            <img :src="item.url" />
          </div>
        </div>
        <!-- tab栏切换 -->
        <van-tabs :active="tabActive">
          <van-tab v-for="v in indexData.tabs" :title="v.title" :key="v.id">
            <Goods @click.native="EmitIndex()" :GoodsList="goodsList"></Goods>
          </van-tab>
        </van-tabs>
        <!-- 垫底空盒子 -->
        <div class="Bottom"></div>
      </div>
    </scroller>
    <!-- 搜索 详情 -->
    <keep-alive>
      <RightAnimate>
        <router-view class="animated" />
      </RightAnimate>
    </keep-alive>
  </div>
</template>

<script>
// 头部组件
import Title from '@/components/Title/Title.vue'
// 插件
import RightAnimate from '@/components/Animate/RightAnimate.vue'
import Goods from '@/pages/public/IndexGoods/Goods.vue'

import { HomeData, HomeGoodsInfo } from '@/api/api.js'
export default {
  name: 'YscShopIndex',
  data () {
    return {
      // 轮播图info
      searchValue: '',
      // tab切换控制
      tabActive: 0,
      // 商品详情切换
      isGoodsInfo: false,
      // 首页信息
      indexData: [],
      // 首页商品信息
      goodsList: [],
    };
  },
  components: {
    Title,
    RightAnimate,
    Goods,
    // GoodsInfo
  },
  created () {
    this.getIndexData();
    // 商品列表
    this.getGoodsList()
  },
  mounted () {
  },
  computed: {
  },
  methods: {
    // 请求index全局数据
    async getIndexData () {
      const { data: res } = await HomeData();
      if (res.status !== 200) return
      this.indexData = res.data
    },
    // // 请求商品列表
    async getGoodsList () {
      const { data: res } = await HomeGoodsInfo();
      if (res.status !== 200) return
      this.goodsList = res.data.goodsInfo
    },
    // 显示搜索页
    goSearch () {
      this.$router.push('/indexSearch')
    },
    // 首页进入详情
    EmitIndex () {
      this.$router.push('/indexGoodsInfo')
    }
  },
};
</script>

<style lang="less" scoped>
// 轮播图
.my-swipe .van-swipe-item {
  color: #fff;
  font-size: 20px;
  height: 170px;
  img {
    width: 100%;
    height: 100%;
  }
}
// 搜索
.van-search {
  transform: translateY(-50%);
  padding: 8px 10px;
  .van-search__content--round {
    background-color: #fff;
  }
}
// index底部导航栏
.van-notice-bar {
  margin-top: -20px;
  .notice-swipe {
    height: 40px;
    line-height: 40px;
    .van-swipe-item {
      // color: #323334;
      color: #f96c2f;
      .van-icon {
        font-weight: bold;
        color: #f96c2f;
      }
    }
  }
}
// index菜单
.van-grid {
  .gridFontSize {
    font-size: 10px;
  }
}
.index {
  // 热销推荐
  .hotRecommend {
    height: 35px;
    line-height: 35px;
    font-size: 14px;
    padding: 0px 10px;
    box-sizing: border-box;
    font-weight: 400;
  }
  // 热销推荐列表
  .hotGoodsList {
    width: 100%;
    padding: 0px 10px;
    box-sizing: border-box;
    font-size: 12px;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    .gotGoods {
      width: 49%;
      height: 80px;
      display: flex;
      align-items: center;
      background-color: #ffffff;
      border-radius: 10px;
      padding: 5px;
      box-sizing: border-box;
      .hotText {
        width: 50%;
        display: flex;
        flex-direction: column;
        align-content: center;
        justify-content: center;
        .oldNum {
          font-size: 10px;
          color: #a6a5a5;
          margin: 5px 0px;
        }
        .price {
          color: #f96c2f;
          font-size: 14px;
        }
        .price::before {
          content: "¥";
        }
      }
      img {
        width: 60%;
        height: 75%;
      }
    }
    .gotGoods {
      margin-bottom: 10px;
    }
  }
  // 垫底空盒子
  .Bottom {
    height: 40px;
  }
}
</style>